package privilege;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import control.Column;
import control.Middlejdbc;

public class GetSmenuServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		response.setContentType("text/html;charset=utf-8");
		
		List<BigNodes> blist = new ArrayList<BigNodes>();
		List<MiddleNodes> mlist = new ArrayList<MiddleNodes>();
		List<LittleNodes> llist=new ArrayList<LittleNodes>();
		
		
		String mgid=request.getParameter("mgid");
		//System.out.println(mgid);
		Middlejdbc m=new Middlejdbc();
		LittleNodes l=null;
		try {
			ArrayList<Column> list=m.queryColumn(mgid);
			for(int i=0;i<list.size();i++)
			{
				Column mu=list.get(i);
				l=new LittleNodes(mu.getCid(),mu.getCname(),mu.getCurl());
				llist.add(l);
			}
			
//			for(int i=0;i<s.length;i++){
//				ArrayList<Column> clist=m.queryColumn(s[i]);
//				c[i]=clist.get(i);
//			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
//		LittleNodes l=null;
//		for(int j=0;j<c.length;j++)
//		{
//			l=new LittleNodes(c[j].getCid(),c[j].getCname(),c[j].getCurl());
//			llist.add(l);
//		}
		
		
		
//		LittleNodes n1=new LittleNodes("1", "权限设置","http://localhost:8080/research/QueryMiddle");
//		LittleNodes n2=new LittleNodes("2", "结果查看","http://localhost:8080/research/SelectAnswerServlet");
//		LittleNodes n3=new LittleNodes("3", "角色管理","http://localhost:8080/research/QueryAdmin");
//		LittleNodes n4=new LittleNodes("4", "用户管理","http://localhost:8080/research/QueryUser");
//		LittleNodes n5=new LittleNodes("5", "题目管理","http://localhost:8080/research/QueryQuestion");
		
//		llist.add(n1);
//		llist.add(n2);
//		llist.add(n3);
//		llist.add(n4);
//		llist.add(n5);
		
		
		MiddleNodes n6 = new MiddleNodes("系统管理",llist);
		mlist.add(n6);
		
		BigNodes n7 = new BigNodes("1",mlist);
		blist.add(n7);
		
		
		JSONArray json=JSONArray.fromObject(blist);//��listת��Ϊjson��ʽ����
		request.setAttribute("json", json);
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}

		
	

}
